﻿Public Class EditAssignment
    Public Response As MessageBoxResult = MessageBoxResult.Cancel
    Public assign As Assignment

    Public Sub New(ByRef value As Assignment)
        InitializeComponent()

        assign = value
        populateCourseList()
        fillForm()
    End Sub

    Public Sub OK_Click()
        saveForm()
        Response = MessageBoxResult.OK
        Me.Hide()
    End Sub

    Public Sub Cancel_Click()
        Response = MessageBoxResult.Cancel
        Me.Hide()
    End Sub

    Public Sub populateCourseList()
        For Each subj As Course In Assignment.courseList
            assignmentCourse.Items.Add(subj.name)
        Next
    End Sub

    Public Sub fillForm()
        assignmentName.Text = assign.name

        If assign.parent Is Nothing Then
            assignmentCourse.SelectedIndex = 0
        Else
            assignmentCourse.SelectedIndex = Assignment.courseList.FindIndex(AddressOf SameCourse)
        End If

        assignmentPriority.SelectedIndex = assign.priority
        assignmentEndDate.SelectedDate = assign.endDate
        assignmentNotes.Text = assign.notes
    End Sub

    Public Sub saveForm()
        assign.name = assignmentName.Text
        assign.priority = assignmentPriority.SelectedIndex
        assign.endDate = assignmentEndDate.SelectedDate
        assign.notes = assignmentNotes.Text
    End Sub

    Private Function SameCourse(ByVal value As Course) As Boolean

        If value.guid = assign.parent.guid Then
            Return True
        Else
            Return False
        End If
    End Function
End Class
